using System;
using System.Collections.Generic;
using DevExpress.XtraBars;
using PharmacyPharnet.Core.CustomEventArgs;

namespace PharmacyPharnet.Core.ContextMenu
{
    public class CustomBasePopUp : PopupMenu
    {
        
        public event BeforeItemExecuteHandler BeforeItemExecute;
        public event AfterItemExecuteHandler AfterItemExecute;

        public CustomBasePopUp()
            : base()
        {
        }

        public CustomBasePopUp(BarManager barManager)
        {
            this.Manager = barManager;
        }

        public void AddMenuItem(CustomButtonBarItem item)
        {
            item.BeforeExecute += new BeforeExecuteHandler(item_BeforeExecute);
            item.AfterExecute += new AfterExecuteHandler(item_AfterExecute);
            this.AddItem(item);
        }

        public CustomButtonBarItem AddMenuItem(string itemName,string itemCaption)
        {
            CustomButtonBarItem item = new CustomButtonBarItem();
            item.Caption = itemCaption;
            item.Manager = this.Manager;
            item.Name = itemName;
            item.BeforeExecute += new BeforeExecuteHandler(item_BeforeExecute);
            item.AfterExecute += new AfterExecuteHandler(item_AfterExecute);
            this.AddItem(item);
            return item;
        }

        void item_AfterExecute(object sender, CustomBaseEventArg e)
        {
            if (AfterItemExecute != null)
            {
                AfterItemExecute(sender, e);
            }
        }

        void item_BeforeExecute(object sender, CustomBaseEventArg e)
        {
            if (BeforeItemExecute != null)
            {
                BeforeItemExecute(sender, e);
            }
        }

        public void HideAllExcept(params Pharmacy.Ultilities.Enums.PopUpItems[] whoAmI)
        {
            foreach (BarButtonItemLink item in this.ItemLinks)
            {
                item.Item.Visibility = BarItemVisibility.Never;
                foreach (Pharmacy.Ultilities.Enums.PopUpItems name in whoAmI)
                {
                    if (((CustomButtonBarItem)item.Item).WhoAmI == name)
                    {
                        item.Item.Visibility = BarItemVisibility.Always;
                        break;
                    }
                }
            }
        }

        public void ShowAllExcept(params string[] itemName)
        {
            foreach (BarButtonItemLink item in this.ItemLinks)
            {
                item.Item.Visibility = BarItemVisibility.Always;
                foreach (string name in itemName)
                {
                    if (item.Item.Name == name)
                    {
                        item.Item.Visibility = BarItemVisibility.Never;
                        break;
                    }
                }
            }
        }
        public void HideAllExcept(params string[] itemName)
        {
            foreach (BarButtonItemLink item in this.ItemLinks)
            {
                item.Item.Visibility = BarItemVisibility.Never;
                foreach (string name in itemName)
                {
                    if (item.Item.Name == name)
                    {
                        item.Item.Visibility = BarItemVisibility.Always;
                       // break;
                    }
                }
            }
        }
        public void ShowMenuItem(string itemName)
        {
            foreach (BarButtonItemLink item in this.ItemLinks)
            {
                item.Item.Visibility = BarItemVisibility.Always;
                if (item.Item.Name == itemName)
                {
                    item.Item.Visibility = BarItemVisibility.Always;
                    break;
                }
            }
        }

        public void ShowAllExcept(params Pharmacy.Ultilities.Enums.PopUpItems[] popupItem)
        {
            foreach (BarButtonItemLink item in this.ItemLinks)
            {
                item.Item.Visibility = BarItemVisibility.Always;
                foreach (Pharmacy.Ultilities.Enums.PopUpItems pItem in popupItem)
                {
                    if (((CustomButtonBarItem)item.Item).WhoAmI == pItem)
                    {
                        item.Item.Visibility = BarItemVisibility.Never;
                        break;
                    }
                }
            }
        }
    }
}
